<!DOCTYPE html>
<html lang="zh-CN">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <meta name="robots" content="noodp" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1">
        <title>react&#43;ts - 肉蛋葱鸡肉粥🍛的博客☕</title><meta name="Description" content=""><meta property="og:title" content="react&#43;ts" />
<meta property="og:description" content="初始化与配置 初始化react&#43;ts项目 create-react-app xxx &ndash;template typescript 规范配置 在引入文件时直接使用根路径：在tsconfig.json中配置baseUrl为&#39;./s" />
<meta property="og:type" content="article" />
<meta property="og:url" content="http://example.org/posts/react&#43;ts/" /><meta property="article:section" content="posts" />
<meta property="article:published_time" content="2021-08-21T10:42:53+08:00" />
<meta property="article:modified_time" content="2021-08-21T10:42:53+08:00" /><meta property="og:site_name" content="肉蛋葱鸡肉粥🍛的博客☕" />

<meta name="twitter:card" content="summary"/>
<meta name="twitter:title" content="react&#43;ts"/>
<meta name="twitter:description" content="初始化与配置 初始化react&#43;ts项目 create-react-app xxx &ndash;template typescript 规范配置 在引入文件时直接使用根路径：在tsconfig.json中配置baseUrl为&#39;./s"/>
<meta name="application-name" content="肉蛋葱鸡肉粥🍛的博客☕">
<meta name="apple-mobile-web-app-title" content="肉蛋葱鸡肉粥🍛的博客☕"><link rel="shortcut icon" type="image/x-icon" href="/favicon.ico" />
        <link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
        <link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png"><link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png"><link rel="manifest" href="/site.webmanifest"><link rel="canonical" href="http://example.org/posts/react&#43;ts/" /><link rel="prev" href="http://example.org/posts/react/" /><link rel="next" href="http://example.org/posts/reacthooks/" /><link rel="stylesheet" href="/lib/normalize/normalize.min.css"><link rel="stylesheet" href="/css/style.min.css"><link rel="stylesheet" href="/lib/fontawesome-free/all.min.css"><link rel="stylesheet" href="/lib/animate/animate.min.css"><script type="application/ld+json">
    {
        "@context": "http://schema.org",
        "@type": "BlogPosting",
        "headline": "react+ts",
        "inLanguage": "zh-CN",
        "mainEntityOfPage": {
            "@type": "WebPage",
            "@id": "http:\/\/example.org\/posts\/react\u002bts\/"
        },"genre": "posts","keywords": "react, typescript","wordcount":  727 ,
        "url": "http:\/\/example.org\/posts\/react\u002bts\/","datePublished": "2021-08-21T10:42:53+08:00","dateModified": "2021-08-21T10:42:53+08:00","publisher": {
            "@type": "Organization",
            "name": "yzuxqz"},"author": {
                "@type": "Person",
                "name": "yzuxqz"
            },"description": ""
    }
    </script></head>
    <body header-desktop="" header-mobile=""><script type="text/javascript">(window.localStorage && localStorage.getItem('theme') ? localStorage.getItem('theme') === 'dark' : ('' === 'auto' ? window.matchMedia('(prefers-color-scheme: dark)').matches : '' === 'dark')) && document.body.setAttribute('theme', 'dark');</script>

        <div id="mask"></div><div class="wrapper"><header class="desktop" id="header-desktop">
    <div class="header-wrapper">
        <div class="header-title">
            <a href="/" title="肉蛋葱鸡肉粥🍛的博客☕">肉蛋葱鸡肉粥🍛的博客☕</a>
        </div>
        <div class="menu">
            <div class="menu-inner"><a class="menu-item" href="/posts/"> 文章 </a><a class="menu-item" href="/tags/"> 标签 </a><a class="menu-item" href="/categories/"> 分类 </a><a class="menu-item" href="/about/"> 关于 </a><span class="menu-item delimiter"></span><a href="javascript:void(0);" class="menu-item language" title="选择语言">简体中文<i class="fas fa-chevron-right fa-fw"></i>
                        <select class="language-select" id="language-select-desktop" onchange="location = this.value;"><option value="/posts/react&#43;ts/" selected>简体中文</option></select>
                    </a><a href="javascript:void(0);" class="menu-item theme-switch" title="切换主题">
                    <i class="fas fa-adjust fa-fw"></i>
                </a>
            </div>
        </div>
    </div>
</header><header class="mobile" id="header-mobile">
    <div class="header-container">
        <div class="header-wrapper">
            <div class="header-title">
                <a href="/" title="肉蛋葱鸡肉粥🍛的博客☕">肉蛋葱鸡肉粥🍛的博客☕</a>
            </div>
            <div class="menu-toggle" id="menu-toggle-mobile">
                <span></span><span></span><span></span>
            </div>
        </div>
        <div class="menu" id="menu-mobile"><a class="menu-item" href="/posts/" title="">文章</a><a class="menu-item" href="/tags/" title="">标签</a><a class="menu-item" href="/categories/" title="">分类</a><a class="menu-item" href="/about/" title="">关于</a><a href="javascript:void(0);" class="menu-item theme-switch" title="切换主题">
                <i class="fas fa-adjust fa-fw"></i>
            </a><a href="javascript:void(0);" class="menu-item" title="选择语言">简体中文<i class="fas fa-chevron-right fa-fw"></i>
                    <select class="language-select" onchange="location = this.value;"><option value="/posts/react&#43;ts/" selected>简体中文</option></select>
                </a></div>
    </div>
</header>
<div class="search-dropdown desktop">
    <div id="search-dropdown-desktop"></div>
</div>
<div class="search-dropdown mobile">
    <div id="search-dropdown-mobile"></div>
</div>
<main class="main">
                <div class="container"><div class="toc" id="toc-auto">
            <h2 class="toc-title">目录</h2>
            <div class="toc-content" id="toc-content-auto"></div>
        </div><article class="page single"><h1 class="single-title animated flipInX">react&#43;ts</h1><div class="post-meta">
            <div class="post-meta-line"><span class="post-author"><a href="https://github.com/yzuxqz" title="Author" target="_blank" rel="noopener noreffer author" class="author"><i class="fas fa-user-circle fa-fw"></i>yzuxqz</a></span>&nbsp;<span class="post-category">收录于 <a href="/categories/react/"><i class="far fa-folder fa-fw"></i>react</a>&nbsp;<a href="/categories/typescript/"><i class="far fa-folder fa-fw"></i>typescript</a>&nbsp;<a href="/categories/%E5%89%8D%E7%AB%AF/"><i class="far fa-folder fa-fw"></i>前端</a></span></div>
            <div class="post-meta-line"><i class="far fa-calendar-alt fa-fw"></i>&nbsp;<time datetime="2021-08-21">2021-08-21</time>&nbsp;<i class="fas fa-pencil-alt fa-fw"></i>&nbsp;约 727 字&nbsp;
                <i class="far fa-clock fa-fw"></i>&nbsp;预计阅读 2 分钟&nbsp;</div>
        </div><div class="details toc" id="toc-static"  kept="">
                <div class="details-summary toc-title">
                    <span>目录</span>
                    <span><i class="details-icon fas fa-angle-right"></i></span>
                </div>
                <div class="details-content toc-content" id="toc-content-static"><nav id="TableOfContents">
  <ul>
    <li><a href="#初始化reactts项目">初始化react+ts项目</a></li>
    <li><a href="#规范配置">规范配置</a></li>
    <li><a href="#mock方案配置">MOCK方案配置</a></li>
  </ul>
</nav></div>
            </div><div class="content" id="content"><h1 id="初始化与配置">初始化与配置</h1>
<h2 id="初始化reactts项目">初始化react+ts项目</h2>
<p>create-react-app xxx &ndash;template typescript</p>
<h2 id="规范配置">规范配置</h2>
<ol>
<li>
<p>在引入文件时直接使用根路径：在tsconfig.json中配置baseUrl为'./src'</p>
</li>
<li>
<p>prettier配置代码自动格式化：https://prettier.io/</p>
<ul>
<li>
<p>npm install &ndash;save-dev &ndash;save-exact prettier</p>
</li>
<li>
<p>新建.prettierrc.json</p>
</li>
<li>
<p>新建.prettierignore，忽略build，coverage</p>
</li>
<li>
<p>为了在commit之前自动格式化：npx mrm lint-staged，package.json中配置扩展名</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span><span class="lnt">5
</span><span class="lnt">6
</span><span class="lnt">7
</span><span class="lnt">8
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-json" data-lang="json"><span class="s2">&#34;husky&#34;</span><span class="err">:</span> <span class="p">{</span>
  <span class="nt">&#34;hooks&#34;</span><span class="p">:</span> <span class="p">{</span>
    <span class="nt">&#34;pre-commit&#34;</span><span class="p">:</span> <span class="s2">&#34;lint-staged&#34;</span>
  <span class="p">}</span>
<span class="p">}</span><span class="err">,</span>
<span class="s2">&#34;lint-staged&#34;</span><span class="err">:</span> <span class="p">{</span>
  <span class="nt">&#34;*.{js,css,md,ts,tsx}&#34;</span><span class="p">:</span> <span class="s2">&#34;prettier --write&#34;</span>
<span class="p">}</span>
</code></pre></td></tr></table>
</div>
</div></li>
<li>
<p>为了避免和eslint冲突</p>
<p>npm install eslint-config-prettier -D</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span><span class="lnt">5
</span><span class="lnt">6
</span><span class="lnt">7
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-json" data-lang="json">  <span class="s2">&#34;eslintConfig&#34;</span><span class="err">:</span> <span class="p">{</span>
    <span class="nt">&#34;extends&#34;</span><span class="p">:</span> <span class="p">[</span>
      <span class="s2">&#34;react-app&#34;</span><span class="p">,</span>
      <span class="s2">&#34;react-app/jest&#34;</span><span class="p">,</span>
      <span class="s2">&#34;prettier&#34;</span>
    <span class="p">]</span>
  <span class="p">}</span>
</code></pre></td></tr></table>
</div>
</div></li>
</ul>
</li>
<li>
<p>commit提交规范：commitlint</p>
</li>
</ol>
<h2 id="mock方案配置">MOCK方案配置</h2>
<ul>
<li>
<p>npm install json-server -g</p>
</li>
<li>
<p>npm install json-server -D</p>
</li>
<li>
<p>script中配置</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-json" data-lang="json"> <span class="s2">&#34;json-server&#34;</span><span class="err">:</span><span class="s2">&#34;json-server __json_server_mock__/db.json --watch&#34;</span>
</code></pre></td></tr></table>
</div>
</div></li>
</ul>
<h1 id="project-list">project-list</h1>
<ul>
<li>
<p>状态提升</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt"> 1
</span><span class="lnt"> 2
</span><span class="lnt"> 3
</span><span class="lnt"> 4
</span><span class="lnt"> 5
</span><span class="lnt"> 6
</span><span class="lnt"> 7
</span><span class="lnt"> 8
</span><span class="lnt"> 9
</span><span class="lnt">10
</span><span class="lnt">11
</span><span class="lnt">12
</span><span class="lnt">13
</span><span class="lnt">14
</span><span class="lnt">15
</span><span class="lnt">16
</span><span class="lnt">17
</span><span class="lnt">18
</span><span class="lnt">19
</span><span class="lnt">20
</span><span class="lnt">21
</span><span class="lnt">22
</span><span class="lnt">23
</span><span class="lnt">24
</span><span class="lnt">25
</span><span class="lnt">26
</span><span class="lnt">27
</span><span class="lnt">28
</span><span class="lnt">29
</span><span class="lnt">30
</span><span class="lnt">31
</span><span class="lnt">32
</span><span class="lnt">33
</span><span class="lnt">34
</span><span class="lnt">35
</span><span class="lnt">36
</span><span class="lnt">37
</span><span class="lnt">38
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-jsx" data-lang="jsx"><span class="kr">import</span> <span class="nx">React</span> <span class="nx">from</span> <span class="s1">&#39;react&#39;</span>
<span class="kr">import</span> <span class="o">*</span> <span class="nx">as</span> <span class="nx">qs</span> <span class="nx">from</span> <span class="s1">&#39;qs&#39;</span>

<span class="kr">import</span> <span class="p">{</span><span class="nx">SearchPanel</span><span class="p">}</span> <span class="nx">from</span> <span class="s2">&#34;./search-panel&#34;</span><span class="p">;</span>
<span class="kr">import</span> <span class="p">{</span><span class="nx">List</span><span class="p">}</span> <span class="nx">from</span> <span class="s2">&#34;./list&#34;</span><span class="p">;</span>
<span class="kr">import</span> <span class="p">{</span><span class="nx">useEffect</span><span class="p">,</span> <span class="nx">useState</span><span class="p">}</span> <span class="nx">from</span> <span class="s2">&#34;react&#34;</span><span class="p">;</span>
<span class="kr">import</span> <span class="p">{</span><span class="nx">cleanObject</span><span class="p">,</span><span class="nx">useDebounce</span><span class="p">,</span><span class="nx">useMount</span><span class="p">}</span> <span class="nx">from</span> <span class="s2">&#34;../../utils&#34;</span><span class="p">;</span>

<span class="kr">export</span> <span class="kr">const</span> <span class="nx">ProjectListScreen</span><span class="o">=</span><span class="p">()=&gt;{</span>
  <span class="kr">const</span> <span class="p">[</span><span class="nx">users</span><span class="p">,</span> <span class="nx">setUsers</span><span class="p">]</span> <span class="o">=</span> <span class="nx">useState</span><span class="p">([])</span>
  <span class="kr">const</span> <span class="p">[</span><span class="nx">param</span><span class="p">,</span> <span class="nx">setParam</span><span class="p">]</span> <span class="o">=</span> <span class="nx">useState</span><span class="p">({</span>
    <span class="nx">name</span><span class="o">:</span> <span class="s1">&#39;&#39;</span><span class="p">,</span>
    <span class="nx">personId</span><span class="o">:</span> <span class="s1">&#39;&#39;</span>
  <span class="p">})</span>
  <span class="kr">const</span> <span class="nx">debounceParam</span><span class="o">=</span> <span class="nx">useDebounce</span><span class="p">(</span><span class="nx">param</span><span class="p">,</span><span class="mi">1000</span><span class="p">)</span>
  <span class="kr">const</span> <span class="p">[</span><span class="nx">list</span><span class="p">,</span> <span class="nx">setList</span><span class="p">]</span> <span class="o">=</span> <span class="nx">useState</span><span class="p">([])</span>
  <span class="c1">//当用户输入关键词或选择select框，param变化
</span><span class="c1"></span>  <span class="nx">useEffect</span><span class="p">(()</span> <span class="p">=&gt;</span> <span class="p">{</span>
    <span class="nx">fetch</span><span class="p">(</span><span class="sb">`http://localhost:3000/projects?</span><span class="si">${</span><span class="nx">qs</span><span class="p">.</span><span class="nx">stringify</span><span class="p">(</span><span class="nx">cleanObject</span><span class="p">(</span><span class="nx">debounceParam</span><span class="p">))</span><span class="si">}</span><span class="sb">`</span><span class="p">).</span><span class="nx">then</span><span class="p">(</span><span class="kr">async</span> <span class="nx">response</span> <span class="p">=&gt;</span> <span class="p">{</span>
      <span class="k">if</span> <span class="p">(</span><span class="nx">response</span><span class="p">.</span><span class="nx">ok</span><span class="p">)</span> <span class="p">{</span>
        <span class="nx">setList</span><span class="p">(</span><span class="kr">await</span> <span class="nx">response</span><span class="p">.</span><span class="nx">json</span><span class="p">())</span>
      <span class="p">}</span>
    <span class="p">})</span>
  <span class="p">},</span> <span class="p">[</span><span class="nx">debounceParam</span><span class="p">])</span>

  <span class="nx">useMount</span><span class="p">(()=&gt;{</span>
    <span class="nx">fetch</span><span class="p">(</span><span class="s1">&#39;http://localhost:3000/users&#39;</span><span class="p">).</span><span class="nx">then</span><span class="p">(</span><span class="kr">async</span> <span class="nx">response</span><span class="p">=&gt;{</span>
      <span class="k">if</span><span class="p">(</span><span class="nx">response</span><span class="p">.</span><span class="nx">ok</span><span class="p">){</span>
        <span class="nx">setUsers</span><span class="p">(</span><span class="kr">await</span> <span class="nx">response</span><span class="p">.</span><span class="nx">json</span><span class="p">())</span>
      <span class="p">}</span>
    <span class="p">})</span>
  <span class="p">})</span>
  <span class="k">return</span> <span class="p">&lt;</span><span class="nt">div</span><span class="p">&gt;</span>
    <span class="p">&lt;</span><span class="nt">SearchPanel</span> <span class="na">param</span><span class="o">=</span><span class="p">{</span><span class="nx">param</span><span class="p">}</span> <span class="na">users</span><span class="o">=</span><span class="p">{</span><span class="nx">users</span><span class="p">}</span> <span class="na">setParam</span><span class="o">=</span><span class="p">{</span><span class="nx">setParam</span><span class="p">}/&gt;</span>
    <span class="p">&lt;</span><span class="nt">List</span> <span class="na">list</span><span class="o">=</span><span class="p">{</span><span class="nx">list</span><span class="p">}</span> <span class="na">users</span><span class="o">=</span><span class="p">{</span><span class="nx">users</span><span class="p">}/&gt;</span>
  <span class="p">&lt;/</span><span class="nt">div</span><span class="p">&gt;</span>
<span class="p">}</span>

</code></pre></td></tr></table>
</div>
</div></li>
<li>
<p>hooks</p>
</li>
<li>
<p>clearObject</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt"> 1
</span><span class="lnt"> 2
</span><span class="lnt"> 3
</span><span class="lnt"> 4
</span><span class="lnt"> 5
</span><span class="lnt"> 6
</span><span class="lnt"> 7
</span><span class="lnt"> 8
</span><span class="lnt"> 9
</span><span class="lnt">10
</span><span class="lnt">11
</span><span class="lnt">12
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-jsx" data-lang="jsx"><span class="kr">export</span> <span class="kr">const</span> <span class="nx">isFalsy</span> <span class="o">=</span> <span class="p">(</span><span class="nx">value</span><span class="p">)</span> <span class="p">=&gt;</span> <span class="p">(</span><span class="nx">value</span> <span class="o">===</span> <span class="mi">0</span> <span class="o">?</span> <span class="kc">false</span> <span class="o">:</span> <span class="o">!</span><span class="nx">value</span><span class="p">);</span>
<span class="c1">//在一个函数中，改变传入的对象本身是不好的
</span><span class="c1"></span><span class="kr">export</span> <span class="kr">const</span> <span class="nx">cleanObject</span> <span class="o">=</span> <span class="p">(</span><span class="nx">object</span><span class="p">)</span> <span class="p">=&gt;</span> <span class="p">{</span>
  <span class="kr">const</span> <span class="nx">result</span> <span class="o">=</span> <span class="p">{</span> <span class="p">...</span><span class="nx">object</span> <span class="p">};</span>
  <span class="nb">Object</span><span class="p">.</span><span class="nx">keys</span><span class="p">(</span><span class="nx">result</span><span class="p">).</span><span class="nx">forEach</span><span class="p">((</span><span class="nx">key</span><span class="p">)</span> <span class="p">=&gt;</span> <span class="p">{</span>
    <span class="kr">const</span> <span class="nx">value</span> <span class="o">=</span> <span class="nx">result</span><span class="p">[</span><span class="nx">key</span><span class="p">];</span>
    <span class="k">if</span> <span class="p">(</span><span class="nx">isFalsy</span><span class="p">(</span><span class="nx">value</span><span class="p">))</span> <span class="p">{</span>
      <span class="k">delete</span> <span class="nx">result</span><span class="p">[</span><span class="nx">key</span><span class="p">];</span>
    <span class="p">}</span>
  <span class="p">});</span>
  <span class="k">return</span> <span class="nx">result</span><span class="p">;</span>
<span class="p">};</span>
</code></pre></td></tr></table>
</div>
</div></li>
</ul>
<h1 id="customhooks">customhooks</h1>
<ul>
<li>
<p>useMount</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span><span class="lnt">5
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-fallback" data-lang="fallback">export const useMount = (callback) =&gt; {
  useEffect(() =&gt; {
    callback();
  }, []);
};
</code></pre></td></tr></table>
</div>
</div></li>
<li>
<p>useDebounce</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt"> 1
</span><span class="lnt"> 2
</span><span class="lnt"> 3
</span><span class="lnt"> 4
</span><span class="lnt"> 5
</span><span class="lnt"> 6
</span><span class="lnt"> 7
</span><span class="lnt"> 8
</span><span class="lnt"> 9
</span><span class="lnt">10
</span><span class="lnt">11
</span><span class="lnt">12
</span><span class="lnt">13
</span><span class="lnt">14
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-jsx" data-lang="jsx"><span class="kr">export</span> <span class="kr">const</span> <span class="nx">useDebounce</span> <span class="o">=</span> <span class="p">(</span><span class="nx">value</span><span class="p">,</span> <span class="nx">delay</span><span class="p">)</span> <span class="p">=&gt;</span> <span class="p">{</span>
  <span class="kr">const</span> <span class="p">[</span><span class="nx">newValue</span><span class="p">,</span> <span class="nx">setNewValue</span><span class="p">]</span> <span class="o">=</span> <span class="nx">useState</span><span class="p">(</span><span class="nx">value</span><span class="p">);</span>
  <span class="nx">useEffect</span><span class="p">(()</span> <span class="p">=&gt;</span> <span class="p">{</span>
    <span class="c1">//每次在value变化以后，设置一个定时器
</span><span class="c1"></span>    <span class="kr">const</span> <span class="nx">timer</span> <span class="o">=</span> <span class="nx">setTimeout</span><span class="p">(()</span> <span class="p">=&gt;</span> <span class="p">{</span>
      <span class="nx">setNewValue</span><span class="p">(</span><span class="nx">value</span><span class="p">);</span>
    <span class="p">},</span> <span class="mi">2000</span><span class="p">);</span>
    <span class="c1">//每次在上一个useEffect处理完以后再运行，第一个effect的timer被第二个effect清理，最后一个无人清理
</span><span class="c1"></span>    <span class="k">return</span> <span class="p">()</span> <span class="p">=&gt;</span> <span class="p">{</span>
      <span class="nx">clearTimeout</span><span class="p">(</span><span class="nx">timer</span><span class="p">);</span>
    <span class="p">};</span>
  <span class="p">},</span> <span class="p">[</span><span class="nx">value</span><span class="p">,</span> <span class="nx">delay</span><span class="p">]);</span>
  <span class="k">return</span> <span class="nx">newValue</span><span class="p">;</span>
<span class="p">};</span>
</code></pre></td></tr></table>
</div>
</div></li>
<li>
<p>more in reacthooks_learn</p>
</li>
</ul>
<h1 id="ts">ts</h1>
<ul>
<li>more in typescript_learn</li>
</ul>
</div><div class="post-footer" id="post-footer">
    <div class="post-info">
        <div class="post-info-line">
            <div class="post-info-mod">
                <span>更新于 2021-08-21</span>
            </div>
            <div class="post-info-license"></div>
        </div>
        <div class="post-info-line">
            <div class="post-info-md"><span>
                            <a class="link-to-markdown" href="/posts/react&#43;ts/index.md" target="_blank">阅读原始文档</a>
                        </span></div>
            <div class="post-info-share">
                <span><a href="javascript:void(0);" title="分享到 Twitter" data-sharer="twitter" data-url="http://example.org/posts/react&#43;ts/" data-title="react&#43;ts" data-via="xxxx" data-hashtags="react,typescript"><i class="fab fa-twitter fa-fw"></i></a><a href="javascript:void(0);" title="分享到 Facebook" data-sharer="facebook" data-url="http://example.org/posts/react&#43;ts/" data-hashtag="react"><i class="fab fa-facebook-square fa-fw"></i></a><a href="javascript:void(0);" title="分享到 WhatsApp" data-sharer="whatsapp" data-url="http://example.org/posts/react&#43;ts/" data-title="react&#43;ts" data-web><i class="fab fa-whatsapp fa-fw"></i></a><a href="javascript:void(0);" title="分享到 Line" data-sharer="line" data-url="http://example.org/posts/react&#43;ts/" data-title="react&#43;ts"><i data-svg-src="/lib/simple-icons/icons/line.min.svg"></i></a><a href="javascript:void(0);" title="分享到 微博" data-sharer="weibo" data-url="http://example.org/posts/react&#43;ts/" data-title="react&#43;ts"><i class="fab fa-weibo fa-fw"></i></a><a href="javascript:void(0);" title="分享到 Myspace" data-sharer="myspace" data-url="http://example.org/posts/react&#43;ts/" data-title="react&#43;ts" data-description=""><i data-svg-src="/lib/simple-icons/icons/myspace.min.svg"></i></a><a href="javascript:void(0);" title="分享到 Blogger" data-sharer="blogger" data-url="http://example.org/posts/react&#43;ts/" data-title="react&#43;ts" data-description=""><i class="fab fa-blogger fa-fw"></i></a><a href="javascript:void(0);" title="分享到 Evernote" data-sharer="evernote" data-url="http://example.org/posts/react&#43;ts/" data-title="react&#43;ts"><i class="fab fa-evernote fa-fw"></i></a></span>
            </div>
        </div>
    </div>

    <div class="post-info-more">
        <section class="post-tags"><i class="fas fa-tags fa-fw"></i>&nbsp;<a href="/tags/react/">react</a>,&nbsp;<a href="/tags/typescript/">typescript</a></section>
        <section>
            <span><a href="javascript:void(0);" onclick="window.history.back();">返回</a></span>&nbsp;|&nbsp;<span><a href="/">主页</a></span>
        </section>
    </div>

    <div class="post-nav"><a href="/posts/react/" class="prev" rel="prev" title="react"><i class="fas fa-angle-left fa-fw"></i>react</a>
            <a href="/posts/reacthooks/" class="next" rel="next" title="hooks">hooks<i class="fas fa-angle-right fa-fw"></i></a></div>
</div>
<div id="comments"></div></article></div>
            </main><footer class="footer">
        <div class="footer-container"><div class="footer-line">由 <a href="https://gohugo.io/" target="_blank" rel="noopener noreffer" title="Hugo 0.89.1">Hugo</a> 强力驱动 | 主题 - <a href="https://github.com/dillonzq/LoveIt" target="_blank" rel="noopener noreffer" title="LoveIt 0.2.10"><i class="far fa-kiss-wink-heart fa-fw"></i> LoveIt</a>
                </div><div class="footer-line"><i class="far fa-copyright fa-fw"></i><span itemprop="copyrightYear">2021</span><span class="author" itemprop="copyrightHolder">&nbsp;<a href="https://github.com/yzuxqz" target="_blank">yzuxqz</a></span></div>
        </div>
    </footer></div>

        <div id="fixed-buttons"><a href="#" id="back-to-top" class="fixed-button" title="回到顶部">
                <i class="fas fa-arrow-up fa-fw"></i>
            </a><a href="#" id="view-comments" class="fixed-button" title="查看评论">
                <i class="fas fa-comment fa-fw"></i>
            </a>
        </div><link rel="stylesheet" href="/lib/katex/katex.min.css"><link rel="stylesheet" href="/lib/katex/copy-tex.min.css"><script type="text/javascript" src="/lib/smooth-scroll/smooth-scroll.min.js"></script><script type="text/javascript" src="/lib/lazysizes/lazysizes.min.js"></script><script type="text/javascript" src="/lib/clipboard/clipboard.min.js"></script><script type="text/javascript" src="/lib/sharer/sharer.min.js"></script><script type="text/javascript" src="/lib/katex/katex.min.js"></script><script type="text/javascript" src="/lib/katex/auto-render.min.js"></script><script type="text/javascript" src="/lib/katex/copy-tex.min.js"></script><script type="text/javascript" src="/lib/katex/mhchem.min.js"></script><script type="text/javascript">window.config={"code":{"copyTitle":"复制到剪贴板","maxShownLines":10},"comment":{},"math":{"delimiters":[{"display":true,"left":"$$","right":"$$"},{"display":true,"left":"\\[","right":"\\]"},{"display":false,"left":"$","right":"$"},{"display":false,"left":"\\(","right":"\\)"}],"strict":false}};</script><script type="text/javascript" src="/js/theme.min.js"></script></body>
</html>
